package com.cn.crmsystem.service.businessService.Impl;

import com.cn.crmsystem.mapper.businessMapper.ReturnedMapper;
import com.cn.crmsystem.pojo.Login;
import com.cn.crmsystem.pojo.Order;
import com.cn.crmsystem.pojo.ResultJson;
import com.cn.crmsystem.pojo.Returned;
import com.cn.crmsystem.service.businessService.ReturnedService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class ReturnedServiceImpl implements ReturnedService{
    @Autowired
    private ReturnedMapper returnedMapper;

    /**
     * 查询回款
     * @param map
     * @return
     */
    @Override
    public ResultJson selectReturnedAll(Map map) {
        List selectReternedAll = returnedMapper.selectReturnedAll(map);
        ResultJson resultJson = new ResultJson();
        if (selectReternedAll != null) {
            resultJson.getSuccess("成功",selectReternedAll);
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;

    }

    @Override
    public ResultJson addReturned(Returned returned, Login login) {
        HashMap<Object,Object> map = new HashMap<>();
        map.put("returned",returned);
        map.put("login",login);
        int addReturned = returnedMapper.addReturned(map);
        ResultJson resultJson = new ResultJson();
        if (addReturned >0) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }

    @Override
    public ResultJson updateReturned(Integer id) {

        int updateReturned = returnedMapper.updateReturned(id);
        ResultJson resultJson = new ResultJson();
        if (updateReturned >0) {
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return  resultJson;
    }

    @Override
    public ResultJson deleteReturned(Integer id) {

        int deleteReturned = returnedMapper.deleteReturned(id);
        ResultJson resultJson = new ResultJson();
        if (deleteReturned>0){
            resultJson.getSuccess("成功");
        } else {
            resultJson.getSuccess("失败", "202");//2002失败
        }
        return resultJson;
    }
}
